package com.czx.common.constants;

public class ResponseResult <T>{
    /**
     * 响应的状态 0失败 1成功 3 未登录
     */
    private int code;
    /**
     * 提示信息 登陆成功 新增成功 修改成功。。。。。
     */
    private String msg;
    /**
     * 成功后获取到的数据 List
     */
    private T t;
    /*设置通用的成功、失败响应*/
    //设置通用的成功响应
    public static ResponseResult createSuccess(){
        //使用ResponseCode 设置默认的成功响应代码和成功响应信息
        return new ResponseResult(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getMsg());
    }
    public static ResponseResult createSuccess(String msg){
        //使用ResponseCode 设置默认的成功响应代码和自定义的响应信息
        return new ResponseResult(ResponseCode.SUCCESS.getCode(),msg);
    }
    public static ResponseResult createSuccess(int code,String msg){
        //使用ResponseCode 设置默认的成功自定义响应代码和自定义响应信息
        return new ResponseResult(code,msg);
    }
    public static <T> ResponseResult createSuccess(T data){
        //使用ResponseCode 设置默认的成功响应代码和成功响应信息,响应数据
        return new ResponseResult(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getMsg(),data);
    }
    public static <T> ResponseResult createResult(int code,String msg,T data){
        return new ResponseResult(code,msg,data);
    }


    //设置通用的失败响应
    public static ResponseResult createFail(){
        //使用ResponseCode 设置默认的失败响应代码和失败响应信息
        return new ResponseResult(ResponseCode.FAIL.getCode(),ResponseCode.FAIL.getMsg());
    }
    public static ResponseResult createFail(String msg){
        //使用ResponseCode 设置默认的失败响应代码和自定义的响应信息
        return new ResponseResult(ResponseCode.FAIL.getCode(),msg);
    }
    public static ResponseResult createFail(int code,String msg){
        //使用ResponseCode 设置默认的失败自定义响应代码和自定义响应信息
        return new ResponseResult(code,msg);
    }
    public static <T> ResponseResult createFail(T data){
        //使用ResponseCode 设置默认的失败响应代码和失败响应信息,响应数据
        return new ResponseResult(ResponseCode.FAIL.getCode(),ResponseCode.FAIL.getMsg(),data);
    }


    public ResponseResult(int code) {
        this.code = code;
    }

    public ResponseResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult() {
    }

    public ResponseResult(T t) {
        this.t = t;
    }

    public ResponseResult(int code, String msg, T t) {
        this.code = code;
        this.msg = msg;
        this.t = t;
    }

    public ResponseResult(int code, T t) {
        this.code = code;
        this.t = t;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getT() {
        return t;
    }

    public void setT(T t) {
        this.t = t;
    }
}
